﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EClinic.pathwaysView.Nodes
{
    public partial class MovableNode : UserControl
    {
         Cursor m_CurrentCursor;
         Boolean m_Moving ;
         Point m_CursorOffset;

    
   
        public MovableNode()
        {
            InitializeComponent();
            NewNode x = new NewNode();
            x.ShowDialog();
            foreach (Control item in this.Controls)
            {
                if (item.Tag == null)
                {
                    item.MouseUp += new MouseEventHandler(MovableNode_MouseUp);
                    item.MouseDown += new MouseEventHandler(MovableNode_MouseDown);
                    item.MouseMove += new MouseEventHandler(MovableNode_MouseMove);

                }
                else
                {
                    if (item.Tag.ToString() != "linedesginer")
                    {
                        item.MouseUp += new MouseEventHandler(MovableNode_MouseUp);
                        item.MouseDown += new MouseEventHandler(MovableNode_MouseDown);
                        item.MouseMove += new MouseEventHandler(MovableNode_MouseMove);
                    }
                }

            }
            foreach (Control item in this.panel1.Controls)
            {
                item.MouseUp += new MouseEventHandler(MovableNode_MouseUp);
                item.MouseDown += new MouseEventHandler(MovableNode_MouseDown);
                item.MouseMove += new MouseEventHandler(MovableNode_MouseMove);

            }
        }

        public void MovableNode_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left )
            {
                m_CurrentCursor = this.Cursor;


                this.Cursor = Cursors.SizeAll;


                m_CursorOffset = e.Location;

            
                m_Moving = true;
            }
        }

        public void MovableNode_Load(object sender, EventArgs e)
        {
            
        }

        public void MovableNode_MouseUp(object sender, MouseEventArgs e)
        {
            m_Moving = false;


            
        }

        public void MovableNode_MouseMove(object sender, MouseEventArgs e)
        {
           if (m_Moving)
           {
               
               Point clientPosition= this.Parent.PointToClient(System.Windows.Forms.Cursor.Position);
               Point adjustedLocation = new Point(clientPosition.X - m_CursorOffset.X,clientPosition.Y - m_CursorOffset.Y);
               this.Location = adjustedLocation;
           }
            

           
        
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }
        public Point  GetRelationInPoint()
        {
            Point x = new Point(button1.Location.X + (button1.Width/2), button1.Location.Y + (button1.Height));

            
            
            return x;

        }
        public Point GetRelationoutPoint()
        {
            Point x = new Point(button2.Location.X + (button1.Width / 2), button2.Location.Y + (button1.Height));



            return x;

        }

        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
          Relation.TempStartpoint = button1.Location;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            EClinic.pathwaysView.Relation.TempStartpoint = button1.Location;
        }
    }
}
